<template>
    <div>
<h1>新增</h1>
<table class="table">
    <thead>
        <tr>
            <td>Kname</td>
            <td>
                <input type="text" v-model="data.Kname">
            </td>
        </tr>
        <tr>
            <td>Ktype</td>
            <td><select v-model="data.Ktype">
                    <option value="">请选择</option>
                    <option value="市场卡">市场卡</option>
                    <option value="次数卡">次数卡</option>
                    <option value="期限卡">期限卡</option>
                </select></td>
        </tr>
        <tr>
            <td>Kroom</td>
            <td><select v-model="data.Kroom">
                    <option value="">请选择</option>
                    <option value="门店1">门店1</option>
                    <option value="门店2">门店2</option>
                    <option value="门店3">门店3</option>
                </select></td>
            
        </tr>
        <tr>
            <td>times</td>
            <td>
            <span v-for="d in fuxuan">
                <input type="checkbox" v-model="box" :value="d">{{ d }}
            </span>
            </td>
        </tr>
        <tr>
            <td>havetimes</td>
            <td><input type="text" v-model="data.havetimes"></td>
        </tr>
        <tr>
            <td>price</td>
            <td><input type="text" v-model="data.price"></td>
        </tr>
        <tr>
            <td>total</td>
            <td><input type="text" v-model="data.total"></td>
        </tr>
        <tr>
            <td>Kstatus</td>
            <td><select v-model="data.Kstatus">
                    <option value="">请选择</option>
                    <option value="下架">下架</option>
                    <option value="上架">上架</option>
                </select></td>
        </tr>
        <tr>
            <td>Imgurl</td>
            <td>
                <input type="file" @change="tupian">
                <img :src="'https://localhost:7111/'+data.Imgurl" style="width: 60px;height: 60px;">
            </td>
        </tr>
        <tr>
            
            <td colspan="2"><input type="button" value="新增" class="btn btn-success" @click="tianj"></td>
            
        </tr>
        
    </thead>
    <tbody></tbody>
</table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref } from 'vue';

const fuxuan = ref(["周一","周二","周三","周四","周五","周六","周日"])
const box = ref([])


const data = ref({
  "id": 0,
  "Kname": "",
  "Ktype": "",
  "Kroom": "",
  "times": "",
  "havetimes": "",
  "price": 0,
  "total": 0,
  "Kstatus": "",
  "Imgurl": "",
  "IsDel": 0
});

const tianj=()=>{
    data.value.times=box.value.toString()
    axios.post("https://localhost:7111/api/Base/Addone",data.value).then(res=>{
        if(res.data==1)
        {
            alert("添加成功");
            location.href="/";
        }
        else{
            alert("添加失败");
            
        }
    })
}
//图片
const tupian = (a :any)=>{
    var f = a.target.files[0]
    var fd = new FormData()
    fd.append("file",f);
    axios.post("https://localhost:7111/api/Imgurll/tupian",fd).then(res=>{
        data.value.Imgurl=res.data
    })
}

const tutu = (a:any)=>{
    var f = a.target.files[0]
    var fs = new FormData()
    fs.append("file",f);

}

</script>

<style scoped>

</style>